//
//  YTUserCommentCell.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/6/6.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTUserCommentCell.h"
#import "YTUserCommentModel.h"

@interface YTUserCommentCell ()

@property (weak, nonatomic) IBOutlet UIImageView *avatarImage;
@property (weak, nonatomic) IBOutlet UILabel *nameText;
@property (weak, nonatomic) IBOutlet UILabel *timeText;
@property (weak, nonatomic) IBOutlet UIView *carStar;
@property (weak, nonatomic) IBOutlet UIView *serviceStar;
@property (weak, nonatomic) IBOutlet UILabel *commentText;

@end

@implementation YTUserCommentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _avatarImage.layer.cornerRadius = 25.0;
    _avatarImage.layer.masksToBounds = YES;
}

- (void)setModel:(YTUserCommentModel *)model {
    _model = model;
    [_avatarImage yy_setImageWithURL:[NSURL URLWithString:model.userFace]
                         placeholder:[UIImage imageNamed:@"public_rect_placeImg"]
                             options:YYWebImageOptionShowNetworkActivity
                          completion:nil];
    _nameText.text = model.userName;
    _timeText.text = model.addTime;
    _commentText.text = model.content;
    
    for (UIView *subView in _carStar.subviews) {
        if ([subView isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)subView;
            if ((button.tag - 1200) < model.car) button.selected = YES;
        }
    }
    
    for (UIView *subView in _serviceStar.subviews) {
        if ([subView isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)subView;
            if ((button.tag - 1210) < model.car) button.selected = YES;
        }
    }
}

- (void)prepareForReuse {
    [super prepareForReuse];
    
    for (UIView *subView in _carStar.subviews) {
        if ([subView isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)subView;
            button.selected = NO;
        }
    }
    
    for (UIView *subView in _serviceStar.subviews) {
        if ([subView isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)subView;
            button.selected = NO;
        }
    }
}

@end
